<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        const p1 = new Promise((resolve, reject) => {
            resolve(1)
        })
         //p1与使用resolve方法等价
        const p2 = Promise.resolve(2);
        const p3 = Promise.reject(3);
        // p1.then(value => { console.log(value);})
        // p2.then(value=>{console.log(value);})
        // p3.then(reason=>{console.log(reason);})
        const pAll = Promise.all([p1, p2,p3])
        //需要传入三个promise对象，当三个异步操作全部成功时执行value操作
        //当出现错误时会执行reason函数
        pAll.then(
            value => {
                console.log("成功的数据", value);
            },
            reason => {
                console.log("失败的数据", reason);
            }
        )
        
        //传入promise对象选择运行最快的执行
        const pRace= Promise.race([p3,p1,p1])
        pRace.then(
            value => {
                console.log("成功的数据race onResolved()", value);
            },
            reason => {
                console.log("失败的数据 race onRejected()", reason);
            }
        )

    </script>

</body>

</html>